#ifndef GLOBALDEFS_H
#define GLOBALDEFS_H

#ifdef __cplusplus
extern "C" {
#endif

typedef int PLAYBACKSESSION;
typedef int (__cdecl *DataProviderCallBack)(PLAYBACKSESSION session, LPVOID param, unsigned char *bufferPtr, UINT len);
typedef long (CALLBACK *DRAWCALLBACK)(PLAYBACKSESSION session, HDC hdc, long lParam);
typedef long (CALLBACK *DECODECALLBACK)(PLAYBACKSESSION session, char * buf, long  size, long width, long height, long stride, long lParam);
typedef long (CALLBACK *VIDEOWNDPAINTCALLBACK)(PLAYBACKSESSION session, HWND hwnd, long lParam);

typedef long (CALLBACK *FrameCALLBACK)(PLAYBACKSESSION session, char * buf, long  size, long lParam );

#ifdef __cplusplus
}
#endif

class CritSec
{
public:
	CritSec()
	{
		InitializeCriticalSection(&_cs);
	}

	~CritSec()
	{
		DeleteCriticalSection(&_cs);
	}

	void Lock()
	{
		EnterCriticalSection(&_cs);
	}

	void Unlock()
	{
		LeaveCriticalSection(&_cs);
	}

private:
	CRITICAL_SECTION _cs;
};

class AutoLock
{
public:
	AutoLock(CritSec &cs)
		:_cs(cs)
	{
		cs.Lock();
	}

	~AutoLock()
	{
		_cs.Unlock();
	}
private:
	CritSec &_cs;
};

template<typename T>
void SafeDeleteArray(T *&p)
{
	if (p != NULL)
	{
		delete[] p;
		p = NULL;
	}
}

void yuv2rgb_32(BYTE *puc_y, int stride_y, 
				BYTE *puc_u, BYTE *puc_v, int stride_uv, 
				BYTE *puc_out, int width_y, int height_y,
				unsigned int _stride_out);

#endif